from django.http import JsonResponse


class ResponseCode:
    @staticmethod
    def resp_200(data=None, message="操作成功"):
        """成功响应"""
        response_data = {
            "code": 200,
            "message": message
        }
        if data is not None:
            response_data["data"] = data
        return JsonResponse(response_data)

    @staticmethod
    def resp_204(message="无数据"):
        """无数据响应"""
        return JsonResponse({
            "code": 204,
            "message": message
        })

    @staticmethod
    def resp_400(message="操作失败"):
        """错误响应"""
        return JsonResponse({
            "code": 400,
            "message": message
        })


response_code = ResponseCode()